package com.heima.wemedia.controller.v1;

import com.heima.model.common.dtos.PageResponseResult;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.common.enums.AppHttpCodeEnum;
import com.heima.model.wemedia.dtos.WmMaterialDto;
import com.heima.wemedia.service.WmMaterialService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author げっしょく
 * @date 2021/11/22
 */
@RestController
@RequestMapping("/api/v1/material")
public class MaterialController {

    @Autowired
    private WmMaterialService wmMaterialService;

    /**
     * 上传素材
     * @param multipartFile
     * @return
     */
    @PostMapping("/upload_picture")
    public ResponseResult uploadPicture(MultipartFile multipartFile) {
        //判断用户是否上传图片
        if (multipartFile != null) {
            return wmMaterialService.uploadIV(multipartFile);
        }
        return ResponseResult.errorResult(AppHttpCodeEnum.PARAM_IMAGE_FORMAT_ERROR, "请上传图片");
    }

    /**
     * 查询素材列表
     * @param dto
     * @return
     */
    @PostMapping("/list")
    public PageResponseResult listIV(WmMaterialDto dto) {

        return wmMaterialService.listIV(dto);
    }

    /**
     * 删除素材
     * @param id
     * @return
     */
    @GetMapping("/del_picture/{id}")
    public ResponseResult delPicture(@PathVariable Integer id) {

        return wmMaterialService.deletePicture(id);
    }

    /**
     * 取消收藏素材
     * @param id
     * @return
     */
    @GetMapping("/cancel_collect/{id}")
    public ResponseResult cancelMaterial(@PathVariable Integer id) {

        return wmMaterialService.cancelMaterial(id);
    }

    /**
     * 收藏素材
     * @param id
     * @return
     */
    @GetMapping("/collect/{id}")
    public ResponseResult collectMaterial(@PathVariable Integer id) {
        return wmMaterialService.collectMaterial(id);
    }
}
